package com.itfenghuang.controller;

import com.itfenghuang.bean.User;
import com.itfenghuang.service.UserService;
import com.itfenghuang.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 页面验证
 * 账号是否可以使用
 */
public class ValidateServlet extends HttpServlet {
    private UserService service=new UserServiceImp();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //1.获取请求参数
        String username = req.getParameter("username");
        if ("".equals(username)){
            //告诉用户不能为空
            resp.getWriter().write("<font color='red'>账号为空</font>");
            return;
        }
        //2.查询方法
        User user = service.selectUser1(username);
        if (user!=null){
            //该账号已经存在
            resp.getWriter().write("<font color='red'>账号已存在</font>");
        }else{
            resp.getWriter().write("<font color='green'>账号可以使用</font>");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            doGet(req, resp);
    }
}
